<template>
  <view class="activeRecordPage">
    <view class="head" :style="[{ height: customBar + 'px' }]">
      <u-navbar
        title="活动预约记录"
        :autoBack="true"
        @leftClick="leftClick"
        :titleStyle="{ fontSize: '34rpx', fontWeight: '500' }"></u-navbar>
    </view>

    <!-- 列表 -->

    <view class="reservationDetail">
      <view class="tabList">
        <view
          v-for="(item, index) in tabList"
          :key="index"
          :class="tabIndex == index ? 'active' : 'myCourse'"
          @tap="handleAll(index)">
          <view class="myCourseRight">{{ item.name }}({{ item.num }})</view>
        </view>
      </view>
      <z-paging
        ref="paging"
        v-model="orderList"
        @query="queryList"
        loading-more-no-more-text="我也是有底线的！"
        default-page-size="5"
        :fixed="false">
        <empty-view slot="empty" />
        <view
          class="recordList"
          v-for="(item, index) in orderList"
          :key="index"
          @click="handlePending(item.id)">
          <view class="recordBottom">
            <view class="recordLeft">
              <image
                class="img"
                :src="HTTP_IMG_URL() + item.activity.images"></image>
            </view>
            <view class="recordRight">
              <view class="title">{{ item.activity.name }}</view>
              <view class="recordLine">预约时间：{{ item.paytime_text }}</view>
              <view class="recordLine">预约人数：{{ item.order_num }}人</view>
            </view>
            <view class="pending" v-if="item.status == '2'">已核销</view>
            <view class="cancel" v-if="item.status == '1'">待核销</view>
            <view class="cancels" v-if="item.status == '3'">已取消</view>
          </view>
        </view>
      </z-paging>
    </view>
  </view>
</template>

<script>
import { HTTP_IMG_URL } from "../../config/app.js";
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      customBar: 88,
      current: 0,
      tabIndex: 0,
      list1: [
        {
          name: "场馆列表",
        },
        {
          name: "场馆预约记录",
        },
      ],
      tabList: [
        {
          name: "全部",
          num: "",
        },
        {
          name: "待核销",
          num: "",
        },
        {
          name: "已核销",
          num: "",
        },
      ],
      orderList: [],
      count: "",
      back: "",
    };
  },

  computed: mapGetters(["isLogin", "uid", "userInfo"]),
  onLoad(params) {
    this.back = params.back;
    // this.getList();
  },
  methods: {
    HTTP_IMG_URL() {
      return HTTP_IMG_URL;
    },
    handlePending(id) {
      uni.navigateTo({
        url: "/pages/reservation/activeReservation?id=" + id,
      });
    },
    handleAll(index) {
      this.tabIndex = index;
      this.$refs.paging.reload();
      this.getList();
    },
    leftClick() {
      if (this.back !== "1") {
        uni.switchTab({
          url: "/pages/index/index",
        });
      }
    },
    queryList(pageNo, pageSize) {
      console.log(pageNo, pageSize, 33);
      var that = this;
      that.$Api.reservation
        .getOrderList({
          page: pageNo,
          pageSize: pageSize,
          status: this.tabIndex,
        })
        .then((res) => {
          console.log(res.data.list.data, 223);
          that.count = res.data.count;
          that.tabList[0].num = that.count.all;
          that.tabList[1].num = that.count.status1;
          that.tabList[2].num = that.count.status2;
          that.$refs.paging.complete(res.data.list.data);
        })
        .catch((res) => {
          this.$refs.paging.complete(false);
        });
    },
    getList(status) {
      var that = this;
      that.$Api.reservation
        .getOrderList({
          status: this.tabIndex,
        })
        .then((res) => {
          this.count = res.data.count;
          this.tabList[0].num = this.count.all;
          this.tabList[1].num = this.count.status1;
          this.tabList[2].num = this.count.status2;
          this.orderList = res.data.list.data;
          console.log(res.data, 23);
        });
    },
    handleDetail(item) {
      console.log(item, 23);
      uni.navigateTo({
        url: "/pages/reservation/cancelOrder?data=" + JSON.stringify(item),
      });
    },
  },
};
</script>

<style lang="scss">
.activeRecordPage {
  height: 100%;
  min-height: 100vh;
  font-family: PingFang SC;
  background: #f5f5f4;
  // padding-bottom: calc(env(safe-area-inset-bottom) / 2);
  .head {
    background: #fff;
  }
  .tab {
    background: #fff;
    height: 90rpx;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 2px;
    ::v-deep .u-tabs {
      width: 60%;
    }
  }

  ::v-deep .u-tabs__wrapper__nav {
    display: flex;
    flex-direction: row;
    position: relative;
    justify-content: space-between;
  }
  ::v-deep .u-tabs__wrapper__nav__item__text {
    flex: 1 !important;
  }
  .reservationBox {
    padding: 0 30rpx;
    margin-top: 20rpx;
    .reservationList {
      width: 100%;
      background: #ffffff;
      box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1),
        inset 0rpx 2rpx 2rpx 0rpx #ffffff;
      border-radius: 28rpx;
      margin-bottom: 20rpx;
      display: flex;
      padding: 20rpx 22rpx;
      box-sizing: border-box;
      .reservationLeft {
        width: 156rpx;
        height: 156rpx;
        background: #ffffff;
        border-radius: 28rpx;
        .img {
          width: 156rpx;
          height: 156rpx;
        }
      }
      .reservationRight {
        margin-left: 20rpx;
        display: flex;
        width: 100%;
        flex-wrap: wrap;
        .reservationName {
          font-weight: 500;
          font-size: 32rpx;
        }
        .reservationLable {
          display: flex;
          margin-top: 64rpx;
          flex-wrap: wrap;

          .label_green {
            padding: 5rpx 20rpx;
            color: #a3c616;
            background: rgba(163, 198, 22, 0.2);
            border-radius: 40rpx;
            font-size: 24rpx;
            margin-right: 10rpx;
            margin-top: 10rpx;
          }
        }
      }
      .voucherBox {
        display: flex;
        align-items: center;
      }
      .reservationVoucher {
        width: 112rpx;
        height: 56rpx;
        background: linear-gradient(90deg, #c1ed1f 0%, #a3c616 100%);
        box-shadow: 0rpx 4rpx 12rpx 0rpx rgba(162, 198, 22, 0.3);
        border-radius: 44rpx;
        font-family: PingFangSC, PingFang SC;
        font-weight: 500;
        font-size: 28rpx;
        color: #ffffff;
        line-height: 56rpx;
        text-align: center;
        font-style: normal;
        flex-shrink: 0;
      }
    }
  }
  .reservationDetail {
    height: 100%;
    padding: 0 30rpx;
  }
  .tabList {
    display: flex;
    margin-top: 20rpx;
    justify-content: space-around;
  }
  .myCourse {
    width: 216rpx;
    height: 88rpx;
    line-height: 88rpx;
    background: #ffffff;
    box-shadow: 0rpx 4rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
    border-radius: 200rpx;
    text-align: center;
  }
  .active {
    width: 216rpx;
    height: 88rpx;
    border-radius: 200rpx;
    line-height: 88rpx;
    background: #a3c616;
    color: #ffffff;
    text-align: center;
  }
  .recordList {
    width: 100%;
    background: #ffffff;
    box-shadow: 0rpx 0rpx 12rpx 0rpx rgba(0, 0, 0, 0.1),
      inset 0rpx 2rpx 2rpx 0rpx #ffffff;
    border-radius: 28rpx;
    margin-top: 20rpx;
    // display: flex;
    padding: 20rpx 22rpx;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    .recordTop {
      display: flex;
      align-items: center;
      .img {
        width: 34rpx;
        margin-right: 10rpx;
      }
    }
    .tip {
      position: absolute;
      height: 108rpx;
      width: 108rpx;
      right: -51rpx;
      top: -53rpx;
      -webkit-transform: rotate(45deg);
      transform: rotate(45deg);
      font-size: 20rpx;
      .name {
        top: 76rpx;
        left: 29rpx;
        color: #fff;
        position: relative;
      }
    }
    .tipused {
      background: #a3c616;
    }
    .tipsuccess {
      background: #e5e5e5;
    }
  }
  .recordBottom {
    margin-top: 12rpx;
    display: flex;
    .recordLeft {
      width: 136rpx;
      height: 136rpx;
      background: #ffffff;
      border-radius: 28rpx;
      .img {
        width: 136rpx;
        height: 136rpx;
      }
    }
    .recordRight {
      margin-left: 12rpx;
      .recordLine {
        display: flex;
        font-size: 26rpx;
        color: #6d7278;
        margin-top: 12rpx;
      }
      .recordTime {
        color: #a3c616;
      }
    }
    .cancel {
      width: 172rpx;
      height: 56rpx;
      background: #fbffed;
      border-radius: 44rpx;
      border: 1rpx solid #a3c616;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 28rpx;
      color: #a3c616;
      line-height: 56rpx;
      text-align: center;
      margin-left: 22rpx;
      margin-top: 80rpx;
    }
    .cancels {
      width: 172rpx;
      height: 56rpx;
      background: #fff;
      border-radius: 44rpx;
      border: 1rpx solid red;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 28rpx;
      color: red;
      line-height: 56rpx;
      text-align: center;
      margin-left: 22rpx;
      margin-top: 80rpx;
    }
    .pending {
      width: 172rpx;
      height: 56rpx;
      background: #f9f9f9;
      border-radius: 44rpx;
      border: 1rpx solid #dadada;
      font-family: PingFangSC, PingFang SC;
      font-weight: 500;
      font-size: 28rpx;
      color: #dadada;
      line-height: 56rpx;
      text-align: center;
      margin-left: 22rpx;
      margin-top: 80rpx;
    }
  }
}
</style>
